package cn.deepmax.anime.web.task;

import cn.deepmax.anime.web.pojo.Section;
import cn.deepmax.anime.web.redis.RedisTemplate;
import cn.deepmax.anime.web.support.WebDriverPool;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.WebDriver;

import java.util.concurrent.CountDownLatch;

@Slf4j
public abstract class AbstractTask implements Runnable{


    protected WebDriverPool<WebDriver> pool;
    protected RedisTemplate redisTemplate;
    protected CountDownLatch latch;

    @SuppressWarnings("unchecked")
    public AbstractTask( WebDriverPool<? extends WebDriver> pool, RedisTemplate redisTemplate, CountDownLatch latch) {

        this.pool = (WebDriverPool<WebDriver>)pool;
        this.redisTemplate = redisTemplate;
        this.latch = latch;
    }


    @Override
    public void run() {
        try{
            runInternal();
        }catch (Throwable t){
            log.error("Failed in task "+this.getClass().getSimpleName(), t);
        }
    }

    public abstract void runInternal();
}
